package com.zzptc.lzh.myapp24;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.lzh.myapp24.entity.XinWen;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getXinWenInfo();
    }

    private void getXinWenInfo() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://v.juhe.cn/toutiao/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        XinWenService xinWenService=retrofit.create(XinWenService.class);
        Map<String,String>map=new HashMap<>();
        map.put("type","top");
        map.put("key","c9d0aa794164156acbd6debf20e39d68");
        Call<XinWen>call=xinWenService.getAll(map);
        call.enqueue(new Callback<XinWen>() {
            @Override
            public void onResponse(Call<XinWen> call, Response<XinWen> response) {
                XinWen xinWen=response.body();
                Log.d(TAG, "onResponse: "+xinWen.getReason());
            }

            @Override
            public void onFailure(Call<XinWen> call, Throwable t) {

            }
        });
    }
}